import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";

const routes: Array<RouteRecordRaw> = [
  {
    // 配置默认路由
    path: "/", // 路由地址
    redirect: "/index", // 重定向
  },
  {
    path: "/index",
    name: "Index",
    component: () => import("../views/Index.vue"),
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "Home",
        meta: {
          title: "首页",
        },
        component: () => import("../views/Home.vue"),
      },
      {
        path: "/hospital",
        name: "Hospital",
        meta: {
          title: "找医院",
        },
        component: () => import("../views/Hospital.vue"),
      },
      {
        path: "/doctor",
        name: "Doctor",
        meta: {
          title: "问医生",
        },
        component: () => import("../views/Doctor.vue"),
      },
      {
        path: "/disease",
        name: "Disease",
        meta: {
          title: "查疾病",
        },
        component: () => import("../views/Disease.vue"),
      },
      {
        path: "/science",
        name: "Science",
        meta: {
          title: "健康科普",
        },
        component: () => import("../views/Science.vue"),
      },
      {
        path: "/exam",
        name: "Exam",
        meta: {
          title: "健康体检",
        },
        component: () => import("../views/Exam.vue"),
      },
      {
        path: "/read",
        name: "Read",
        meta: {
          title: "健康必读",
        },
        component: () => import("../views/Read.vue"),
      },
    ],
  },
  {
    path: "/:catchAll(.*)",
    name: "404",
    component: () => import("../views/404.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

// router.beforeEach((to, from, next) => {

// });

export default router;
